package com.tgy.leetcode;

/**
 * @Author: tgy
 * @Date: 12/24/20 2:20 PM
 */
public class _剑指_Offer_62_圆圈中最后剩下的数字 {

    public int lastRemaining(int n, int m) {

        // f(n,m) = (f(n-1,m) + m)%n

//        f(1,m) = 0;

        int start = 0;

        for (int i = 2; i <= n; i++) {

            start = (start + m) % i;
        }

        return start;
    }
}
